<template>
	<view>
		<u-navbar title-color="#333" title-bold title-size="36" title="编辑信息" :border-bottom="false"></u-navbar>
		<view class="sz-div u-m-t-22">
			<view class="item flex flex_sb">
				<view class="">
					<view class="">
						头像 <span class="xing">*</span>
					</view>
					<view class="font_12_999 u-m-t-4">
						头像会用于平台展示，请上传形像照
					</view>

				</view>
				<view class="flex" @click="chooseImage">
					<image class="headimg u-m-r-4" :src="detail.avatar" mode="aspectFill"></image>
					<u-icon name="arrow-right" color="#333" size="24"></u-icon>
				</view>
			</view>
			<view class="item flex flex_sb">
				<view class="">
					姓名
				</view>
				<view class="flex">
					<view class="u-m-r-4 item-vl">
						{{detail.name}}
					</view>
				</view>
			</view>
			<view class="item flex flex_sb">
				<view class="">个人简介<span class="xing">*</span></view>
				<view class="flex" @click="ncshuru(1,'个人简介')">
					<view class="u-m-r-4 item-vl line_1">
						{{detail.profile_note?detail.profile_note:'请输入'}}
					</view>
					<u-icon name="arrow-right" color="#333" size="24"></u-icon>
				</view>
			</view>
			<view class="item flex flex_sb">
				<view class="">教育背景<span class="xing">*</span></view>
				<view class="flex" @click="ncshuru(2,'教育背景')">
					<view class="u-m-r-4 item-vl line_1">
						{{detail.educate_note?detail.educate_note:'请输入'}}
					</view>
					<u-icon name="arrow-right" color="#333" size="24"></u-icon>
				</view>
			</view>
			<view class="item flex flex_sb">
				<view class="">荣誉奖项<span class="xing">*</span></view>
				<view class="flex" @click="ncshuru(3,'荣誉奖项')">
					<view class="u-m-r-4 item-vl line_1">
						{{detail.honor_note?detail.honor_note:'请输入'}}
					</view>
					<u-icon name="arrow-right" color="#333" size="24"></u-icon>
				</view>
			</view>
		</view>
		<view class="" style="width: 100%;height: 170rpx;"></view>
		<view class="btn-bo">
			<button class="btn_login_btn" @click="submit">
				提交资料
			</button>
		</view>



		<u-popup v-model="ncShow" mode="bottom" border-radius="32" closeable>
			<view class="mxpo-div ">
				<view class="font_weight  font_17_333">
					{{xgText}}
				</view>
				<!-- <view class="u-m-t-30" v-if="xgtype==1">
					<view class="font_weight  font_16_333">
						系统默认
					</view>
					<view class="font_12_999 u-m-t-16">
						执业年限0年，有相关的法律咨询可通过一对一咨询服务向我提问。
					</view>
				</view> -->
				<view class="jinji-item">
					<view class="jinji-input">
						<u-input type="textarea" height="220" v-model="xgValue" />
					</view>
				</view>
				<view class="bob-btn u-m-t-58" @click="changeNick">
					确定
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				detail: [],
				ncShow: false,
				nickname: '',
				action: '',
				xgText: '',
				xgtype: '',
				xgValue: '',
				
				
			}
		},
		onLoad() {
			this.getInfo()
		},
		methods: {
			//个人信息
			getInfo() {
				this.$api({
					url: '/lawyer/getLawyer',
					method: 'get',
					data: {
						token:uni.getStorageSync("token")
					},
				}).then(res => {
					if (res.code == 1) {
						this.detail = res.data
					} 
				})
				
			},
			ncshuru(e,t) {
				this.xgText = t
				this.xgtype = e
				this.ncShow = true
				if(e==1){
					this.xgValue = this.detail.profile_note
				}else if(e==2){
					this.xgValue = this.detail.educate_note
				}else if(e==3){
					this.xgValue = this.detail.honor_note
				}
				
				
			},
			changeNick() {
				if (this.xgtype == 1) { //1个人简介  2教育背景  3荣誉奖项
					this.detail.profile_note = this.xgValue
					this.xgValue = ''
				}else if(this.xgtype == 2){
					this.detail.educate_note = this.xgValue
					this.xgValue = ''
				}else if(this.xgtype == 3){
					this.detail.honor_note = this.xgValue
					this.xgValue = ''
				}
				this.ncShow = false


				
			},
			submit(){
				this.$api({
					url: '/lawyer/saveLawyer',
					method: 'post',
					data: this.detail,
				}).then(res => {
					if (res.code == 1) {
						this.getInfo()
						uni.showToast({
							title: '修改成功',
							icon: 'none'
						})
					}
				})
				
				
			},
			chooseImage() {
				let that = this
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择

					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						uni.uploadFile({
							url: that.$config.uploadUrl,
							filePath: tempFilePaths[0],
							name: 'file',
							formData: {
								token: uni.getStorageSync('token')
							},
							success: (uploadFileRes) => {
								console.log(uploadFileRes.data);

								// that.detail.image = JSON.parse(uploadFileRes.data).data.path
								// console.log(that.detail.image)
								if (JSON.parse(uploadFileRes.data).code != 1) {
									uni.showToast({
										title: JSON.parse(uploadFileRes.data).msg,
										icon: 'none'
									})
									return
								}

								that.detail.avatar = JSON.parse(uploadFileRes.data).data.path
								that.detail.token = uni.getStorageSync("token")
								that.$api({
									url: '/lawyer/saveLawyer',
									method: 'post',
									data: that.detail,
								}).then(res => {
									if (res.code == 1) {
										that.getInfo()
										uni.showToast({
											title: '修改头像成功',
											icon: 'none'
										})
									}
								})
							}
						});
					}

				});
			},

			edit(e) {
				if (e == 1) {
					uni.navigateTo({
						url: "/pages/mine/editPhone"
					})
				}
				if (e == 2) {
					uni.navigateTo({
						url: "/pages/mine/editPwd"
					})
				}
			}
		}
	}
</script>

<style scoped lang="scss">
	.btn-bo {
		width: 750rpx;
		height: 120rpx;
		background: #FFFFFF;
		box-shadow: 0rpx -2rpx 8rpx 2rpx rgba(0, 0, 0, 0.14);
		padding-top: 14rpx;
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 9;

		.btn_login_btn {
			width: 686rpx;
			height: 90rpx;
			background: linear-gradient(180deg, #FA2D2D 0%, #F40000 100%);
			border-radius: 46rpx 46rpx 46rpx 46rpx;
			// margin-top: 116rpx;
			font-size: 36rpx;
			color: #fff;
			line-height: 90rpx;
			margin-left: 32rpx;
			text-align: center;
			font-weight: bold;
		}
	}

	.xing {
		color: #FF0000;
	}

	.sz-div {
		background-color: #fff;
		width: 686rpx;
		// height: 550rpx;
		background: #FFFFFF;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		margin: 0 auto;
		padding: 0 24rpx;

		.item {
			width: 100%;
			height: 110rpx;
			border-bottom: 1px solid #eee;

			.item-vl {
				font-size: 32rpx;
				color: #9695A3;
				width: 256rpx;
				text-align: right;
			}

			.headimg {
				width: 68rpx;
				height: 80rpx;
				border-radius: 8rpx;
			}
		}
	}

	.mxpo-div {
		width: 750rpx;
		// height: 1034rpx;
		background: #FFFFFF;
		padding: 40rpx 24rpx 40rpx;

		.mxt {
			color: #16053C;
		}

		.bob-btn {
			width: 686rpx;
			height: 90rpx;
			background: linear-gradient(180deg, #FA2D2D 0%, #F40000 100%);
			border-radius: 46rpx 46rpx 46rpx 46rpx;
			text-align: center;
			line-height: 88rpx;
			font-size: 36rpx;
			color: #FFF7D2;
		}
	}

	.jinji-item {
		margin-top: 36rpx;

		.jinji-text {
			font-size: 32rpx;
			color: #3F464E;
		}

		.jinji-input {
			width: 690rpx;
			height: 250rpx;
			background: #EDEDED;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			margin-top: 24rpx;
			padding: 8rpx 24rpx;
		}

		.jinji-input2 {
			height: 268rpx;
		}
	}
</style>